package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.News;
import com.ruoyi.system.mapper.NewsMapper;
import com.ruoyi.system.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * newsService业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-05
 */
@Service
public class NewsServiceImpl implements INewsService 
{
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> selectValid(String ppnewname, int ppStartIndex, int ppPageSize) {
        return newsMapper.selectValid(ppnewname, ppStartIndex, ppPageSize);
    }

    @Override
    public int countValid( String ppnewname) {
        Object mmCount = newsMapper.countValid(ppnewname);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    @Override
    public List<News> selectAll(String ppnewname, int ppStartIndex,  int ppPageSize) {
        return newsMapper.selectAll(ppnewname,ppStartIndex, ppPageSize);
    }

    @Override
    public int countAll(String ppnewname) {
        Object mmCount = newsMapper.countAll(ppnewname);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    @Override
    public int getMaxNumber() {
        Object mmCount = newsMapper.getMaxNumber();
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    /**
     * 查询news
     * 
     * @param id news主键
     * @return news
     */
    @Override
    public News selectNewsById(String id)
    {
        return newsMapper.selectNewsById(id);
    }

    /**
     * 查询news列表
     * 
     * @param news news
     * @return news
     */
    @Override
    public List<News> selectNewsList(News news)
    {
        return newsMapper.selectNewsList(news);
    }

    /**
     * 新增news
     * 
     * @param news news
     * @return 结果
     */
    @Override
    public int insertNews(News news)
    {
        news.setCreateTime(DateUtils.getNowDate());
        return newsMapper.insertNews(news);
    }

    /**
     * 修改news
     * 
     * @param news news
     * @return 结果
     */
    @Override
    public int updateNews(News news)
    {
        news.setUpdateTime(DateUtils.getNowDate());
        return newsMapper.updateNews(news);
    }

    /**
     * 批量删除news
     * 
     * @param ids 需要删除的news主键
     * @return 结果
     */
    @Override
    public int deleteNewsByIds(String[] ids)
    {
        return newsMapper.deleteNewsByIds(ids);
    }

    /**
     * 删除news信息
     * 
     * @param id news主键
     * @return 结果
     */
    @Override
    public int deleteNewsById(String id)
    {
        return newsMapper.deleteNewsById(id);
    }
}
